package com.lucy.common.converter;

import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.lang.Validator;
import com.lucy.common.utils.JsonUtil;

import javax.persistence.AttributeConverter;
import java.util.ArrayList;
import java.util.List;

/**
 * @author kindear
 */
@Deprecated
public class JpaListLongConverter implements AttributeConverter<List<Long>,String> {
    @Override
    public String convertToDatabaseColumn(List<Long> o) {
        // BUG FIX 2021-11-29 空值转化
        if(Validator.isEmpty(o)){
            List<Long> t = new ArrayList<>();
            return JsonUtil.obj2String(o);
        }
        return JsonUtil.obj2String(o);
    }

    @Override
    public List<Long> convertToEntityAttribute(String s) {
        // BUG FIX 2021-11-29 空值转化
        if(Validator.isEmpty(s)){
            return new ArrayList<Long>();
        }
        return JsonUtil.string2Obj(s,List.class);
    }
}